﻿<template>
	<div class="busOrder-container">
		<el-card shadow="hover" :body-style="{ paddingBottom: '0' }">
			<el-form :model="queryParams" ref="queryForm" :inline="true">
				<el-form-item label="订单编码">
					<el-input v-model="queryParams.orderCode" clearable="" placeholder="请输入订单编码" />
				</el-form-item>
				<el-form-item>
					<el-button-group>
						<el-button type="primary" icon="ele-Search" @click="handleQuery" v-auth="'busOrder:page'"> 查询 </el-button>
						<el-button icon="ele-Refresh" @click="() => (queryParams = {})"> 重置 </el-button>
					</el-button-group>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="ele-Plus" @click="openAddBusOrder" v-auth="'busOrder:add'"> 新增 </el-button>
				</el-form-item>
			</el-form>
		</el-card>
		<el-card class="full-table" shadow="hover" style="margin-top: 8px">
			<el-table :data="tableData" style="width: 100%" v-loading="loading" tooltip-effect="light" row-key="id" border="">
				<el-table-column type="index" label="序号" width="55" align="center" />
				<el-table-column prop="id" label="主键Id" show-overflow-tooltip="" />
				<el-table-column prop="tenantId" label="租户Id" show-overflow-tooltip="" />
				<el-table-column prop="orderCode" label="订单编码" show-overflow-tooltip="" />
				<el-table-column prop="amount" label="订单总金额" show-overflow-tooltip="" />
				<el-table-column prop="itemCount" label="子表行数量" show-overflow-tooltip="" />
				<el-table-column prop="storeCode" label="门店" show-overflow-tooltip="">
					<template #default="scope">
						<span>{{ scope.row.busStroeSName }}</span>
					</template>
				</el-table-column>
				<el-table-column prop="createTime" label="创建时间" show-overflow-tooltip="" />
				<el-table-column prop="updateTime" label="更新时间" show-overflow-tooltip="" />
				<el-table-column prop="createUserId" label="创建者Id" show-overflow-tooltip="" />
				<el-table-column prop="updateUserId" label="修改者Id" show-overflow-tooltip="" />
				<el-table-column prop="isDelete" label="软删除" show-overflow-tooltip="">
					<template #default="scope">
						<el-tag v-if="scope.row.isDelete"> 是 </el-tag>
						<el-tag type="danger" v-else> 否 </el-tag>
					</template>
					<!-- v-if="auth('busOrder:edit') || auth('busOrder:delete')"d -->
				</el-table-column>
				<el-table-column label="操作" width="200" align="center" fixed="right" show-overflow-tooltip="">
					<template #default="scope">
						<el-button icon="ele-Edit" size="small" text="" type="primary" @click="openEditBusOrder(scope.row)" v-auth="'busOrder:edit'"> 编辑 </el-button>
						<el-button icon="ele-Memo" size="small" text type="primary" @click="openDictDataDialog(scope.row)" v-auth="'busOrder:page'"> 明细 </el-button>
						<el-button icon="ele-Delete" size="small" text="" type="primary" @click="delBusOrder(scope.row)" v-auth="'busOrder:delete'"> 删除 </el-button>
					</template>
				</el-table-column>
			</el-table>
			<el-pagination
				v-model:currentPage="tableParams.page"
				v-model:page-size="tableParams.pageSize"
				:total="tableParams.total"
				:page-sizes="[10, 20, 50, 100]"
				small=""
				background=""
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				layout="total, sizes, prev, pager, next, jumper"
			/>
			<editDialog ref="editDialogRef" :title="editBusOrderTitle" @reloadTable="handleQuery" />
			<dictDataDialog ref="dictDataDialogRef" :isShowDialog="isShowDialog" />
		</el-card>
	</div>
</template>

<script lang="ts" setup="" name="busOrder">
import { onMounted, reactive, ref } from 'vue';
import { ElMessageBox, ElMessage } from 'element-plus';
import { auth } from '/@/utils/authFunction';
//import { formatDate } from '/@/utils/formatTime';
import SubOrderDialog from '/@/views/main/busOrder/component/dictDataDialog.vue';
import dictDataDialog from './component/dictDataDialog.vue';

import editDialog from '/@/views/main/busOrder/component/editDialog.vue';
import { pageBusOrder, deleteBusOrder } from '/@/api/main/busOrder';

const editDialogRef = ref();
const dictDataDialogRef = ref<InstanceType<typeof SubOrderDialog>>();
// const dictDataDialogRef = ref();

const isShowDialog = ref(false);

const loading = ref(false);
const tableData = ref<any>([]);

const state = reactive({
	loading: false,

	queryParams: {
		name: undefined,
		code: undefined,
	},
	tableParams: {
		page: 1,
		pageSize: 20,
		total: 0 as any,
	},
	editDictTypeTitle: '',
});

onMounted(async () => {
	handleQuery();
});

const queryParams = ref<any>({});
const tableParams = ref({
	page: 1,
	pageSize: 10,
	total: 0,
});
const editBusOrderTitle = ref('');

// 查询操作
const handleQuery = async () => {
	loading.value = true;
	var res = await pageBusOrder(Object.assign(queryParams.value, tableParams.value));
	tableData.value = res.data.result?.items ?? [];
	tableParams.value.total = res.data.result?.total;
	loading.value = false;
};

// 打开新增页面
const openAddBusOrder = () => {
	editBusOrderTitle.value = '添加订单列表';
	editDialogRef.value.openDialog({});
};
//明细
const openDictDataDialog = (row: any) => {
	// console.log(row);
	dictDataDialogRef.value?.openDialog(row);
};

// 打开编辑页面
const openEditBusOrder = (row: any) => {
	editBusOrderTitle.value = '编辑订单列表';
	editDialogRef.value.openDialog(row);
};

// 删除
const delBusOrder = (row: any) => {
	ElMessageBox.confirm(`确定要删除吗?`, '提示', {
		confirmButtonText: '确定',
		cancelButtonText: '取消',
		type: 'warning',
	})
		.then(async () => {
			await deleteBusOrder(row);
			handleQuery();
			ElMessage.success('删除成功');
		})
		.catch(() => {});
};

// 改变页面容量
const handleSizeChange = (val: number) => {
	tableParams.value.pageSize = val;
	handleQuery();
};

// 改变页码序号
const handleCurrentChange = (val: number) => {
	tableParams.value.page = val;
	handleQuery();
};

handleQuery();
</script>


